home *** CD-ROM | disk | FTP | other *** search
/ Graphics & Sound Program…ng Techniques for the Mac / Graphics and Sound Programming Techniques for the Mac.iso / M&T Graphics & Sound Examples / Symantec Versions / C07 QuickTime Movies / P02 Movie Dialog / MovieDialog.c next >
Encoding:
C/C++ Source or Header  |  1995-08-31  |  4.3 KB  |  168 lines  |  [TEXT/KAHL]

  1. //____________________________________________________________
  2. //    MovieDialog.c
  3. //
  4. //    Copyright © Dan Parks Sydow, 1995
  5. //    From the book:
  6. //    "Graphics and Sound Programming Techniques for the Mac",
  7. //    M&T Books, 1995
  8.  
  9.  
  10. //____________________________________________________________
  11.  
  12. #include <Movies.h>   
  13.  
  14.  
  15. //____________________________________________________________
  16.  
  17. void  InitializeAllToolboxes( void );
  18. void  OpenDisplayDialog( void );
  19. void  LoadAndRunMovie( DialogPtr, Str255 );
  20.  
  21.  
  22. //____________________________________________________________
  23.  
  24. #define         rMovieWindow               128
  25. #define         rMovieDialog               128
  26. #define         kQuitButton                  1
  27. #define         kClearButton                 2
  28. #define         kApolloButton                3
  29. #define         kVenusButton                 4
  30. #define         kFrameButton                 5
  31. #define         kMovieFramePicture         128
  32. #define         kFramePixelSize              4
  33. #define         kApolloMovieName   "\p:Movie ƒ:Apollo Launch"
  34. #define         kVenusMovieName    "\p:Movie ƒ:Venus Probe"
  35.  
  36.  
  37. //____________________________________________________________
  38.  
  39. Boolean  gAllDone  = false;
  40.  
  41.  
  42. //____________________________________________________________
  43.  
  44. void  main( void )
  45. {   
  46.    InitializeAllToolboxes();
  47.  
  48.    OpenDisplayDialog();
  49. }
  50.  
  51.  
  52. //____________________________________________________________
  53.  
  54. void  OpenDisplayDialog( void )
  55. {
  56.    DialogPtr  theDialog;
  57.    short      theItem;
  58.    Boolean    allDone = false;
  59.    short      theType;    
  60.    Handle     theHandle;              
  61.    Rect       theRect;     
  62.    PicHandle  thePicture;
  63.  
  64.    theDialog = GetNewDialog( rMovieDialog, nil, (WindowPtr)-1L );
  65.    ShowWindow( theDialog );
  66.    SetPort( theDialog );
  67.    
  68.    while ( allDone == false )
  69.    {
  70.       ModalDialog( nil, &theItem );
  71.          
  72.       switch ( theItem )
  73.       {
  74.          case kApolloButton:
  75.             LoadAndRunMovie( theDialog, kApolloMovieName );
  76.             break;
  77.  
  78.          case kVenusButton:
  79.             LoadAndRunMovie( theDialog, kVenusMovieName );
  80.             break;
  81.  
  82.          case kClearButton:
  83.             GetDialogItem( theDialog, kFrameButton, &theType, &theHandle, &theRect ); 
  84.             thePicture = GetPicture( kMovieFramePicture );
  85.             DrawPicture( thePicture, &theRect );
  86.             break;
  87.             
  88.          case kQuitButton:
  89.             allDone = true;
  90.             break;
  91.       }
  92.    }
  93.    
  94.    DisposeDialog( theDialog ); 
  95. }
  96.  
  97.  
  98. //____________________________________________________________
  99.  
  100. void  LoadAndRunMovie( DialogPtr theDialog, Str255 theMovieName )
  101. {
  102.    OSErr    theError;
  103.    FSSpec   theFSSpec;
  104.    short    theFileRefNum;
  105.    Movie    theMovie;
  106.    short    theMovieResID = 0;   
  107.    Str255   theMovieResName;
  108.    Boolean  wasAltered;
  109.    Rect     theMovieBox;
  110.    short    theType;    
  111.    Handle   theHandle;              
  112.    Rect     theRect;     
  113.  
  114.    theError = FSMakeFSSpec( 0, 0L, theMovieName, &theFSSpec );
  115.    theError = OpenMovieFile( &theFSSpec, &theFileRefNum, fsRdPerm );
  116.    theError = NewMovieFromFile( &theMovie, theFileRefNum, &theMovieResID,
  117.                                  theMovieResName, newMovieActive, &wasAltered );
  118.                                          
  119.    CloseMovieFile( theFileRefNum );
  120.    
  121.    SetMovieGWorld( theMovie, (CGrafPtr)theDialog, nil); 
  122.       
  123.    GetMovieBox( theMovie, &theMovieBox );
  124.    OffsetRect( &theMovieBox, -theMovieBox.left, -theMovieBox.top );
  125.    GetDialogItem( theDialog, kFrameButton, 
  126.                   &theType, &theHandle, &theRect ); 
  127.    OffsetRect( &theMovieBox, theRect.left + kFramePixelSize, theRect.top + kFramePixelSize );
  128.    SetMovieBox( theMovie, &theMovieBox );
  129.  
  130.    GoToBeginningOfMovie( theMovie );
  131.  
  132.    StartMovie( theMovie );
  133.    
  134.    do
  135.    {
  136.       MoviesTask(theMovie, 0);
  137.    }
  138.    while ( IsMovieDone( theMovie ) == false );
  139.  
  140.    DisposeMovie( theMovie );
  141. }
  142.  
  143.  
  144. //____________________________________________________________
  145.  
  146. void  InitializeAllToolboxes( void )
  147. {
  148.    OSErr  theError;
  149.    long   theResult;
  150.  
  151.    InitGraf( &qd.thePort );
  152.    InitFonts();
  153.    InitWindows();
  154.    InitMenus();
  155.    TEInit();
  156.    InitDialogs( 0L );
  157.    FlushEvents( everyEvent, 0 );
  158.    InitCursor();
  159.  
  160.    theError = Gestalt( gestaltQuickTime, &theResult );
  161.    if ( theError != noErr )
  162.       ExitToShell();
  163.                                                  
  164.    theError = EnterMovies();  
  165.    if ( theError != noErr )
  166.       ExitToShell(); 
  167. }
  168.